package com.tyust.service;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tyust.dao.StaffDao;
import com.tyust.entity.PageUtils;
import com.tyust.entity.Staff;
import com.tyust.entity.User;
import com.tyust.util.commons.DateUtil;

@Service("staffService")
public class StaffServiceImpl implements StaffService {

	@Autowired
	private StaffDao staffDao;
	@Override
	public void add(Staff staff) throws SQLException {
		staffDao.add(staff);
	}

	public PageUtils searchStaffInfo(Staff staff) {
		List<Staff> list = staffDao.searchStaffInfo(staff);
		for(Staff staffInfo:list) {
			staffInfo.setEntryDateStr(DateUtil.dateTostr(staffInfo.getEntryDate()));
			staffInfo.setBirthDateStr(DateUtil.dateTostr(staffInfo.getBirthDate()));
		}
		return toPageBean(list,staff);
	}
	private PageUtils toPageBean(List<Staff> list,Staff staff){
		Integer tr= findStaffCount(staff);
		return new PageUtils(list,tr,staff.getLimit(),staff.getPage());
	}
	@Override
	public int findStaffCount(Staff staff) {
		return staffDao.findStaffCount(staff);
	}

	@Override
	public Staff getStaffByNo(Staff staff) {
		return staffDao.getStaffByNo(staff);
	}

	@Override
	public void updateStaffInfo(Staff staff) {
		staffDao.updateStaffInfo(staff);
	}

	@Override
	public void deleteByNo(String staffNo) {
		staffDao.deleteByNo(staffNo);
	}

}
